﻿package  {
	
	import com.greensock.plugins.FrameBackwardPlugin;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import com.greensock.*; 
	import com.greensock.easing.*;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundMixer;

	public class Menu extends MovieClip {
		
		public var menuProjectRef:MovieClip;
		public var InstrucoesMC:Instrucoes_MC;
		public var Hudmcd:MovieClip;
		public static var JogoMC:MovieClip;
		public var soundChannel:SoundChannel;
		[Embed(source = "../lib/Sons/somBotoesMenu.mp3")]
		public var botaoMenuclass:Class;
		public var btnMenusnd:Sound;

		[Embed(source = "../lib/Sons/somMenu.mp3")]
		public var Menusndclass:Class;
		public var Menusnd:Sound;						
		
		public function Menu() {
			menuProjectRef = this;
		
			btnMenusnd = (new botaoMenuclass) as Sound;
			Menusnd =  (new Menusndclass) as Sound;
			soundChannel = Menusnd.play(0, 9999);
			
			Hudmcd = new txtLevel_MC();
			menuProjectRef.addChild(Hudmcd);
			
			var menuMC:MovieClip = new mc_fundoMenu();
			//var menuMC:MovieClip = new TelaInicial_MC();
			
			menuMC.x = stage.stageWidth / 2;
			menuMC.y = menuMC.height - stage.stageHeight - 79;
			this.addChild(menuMC);
			
			menuMC.btnJogar.addEventListener(MouseEvent.CLICK, IniciaTimer);
			menuMC.btnInstrucoes.addEventListener(MouseEvent.CLICK, Instrucoes);
			
			
			InstrucoesMC = new Instrucoes_MC();
			InstrucoesMC.x = -400;
			InstrucoesMC.y = stage.stageHeight / 2;
			InstrucoesMC.scaleX = 0;
			InstrucoesMC.scaleY = 0;
			InstrucoesMC.addEventListener(MouseEvent.CLICK, RemoveHelp);
			menuProjectRef.addChild(InstrucoesMC);				
		}
		
		private function ResetaAudio():void {
			Menusnd.play();
		}		
		
		private function IniciaTimer(e:MouseEvent):void {	
			btnMenusnd.play();
			var tIniciaJogo:Timer = new Timer(5200, 1);
			tIniciaJogo.addEventListener(TimerEvent.TIMER, IniciaJogo);
			tIniciaJogo.start();
		}
		
		public function IniciaJogo(e:TimerEvent):void {
			SoundMixer.stopAll();
			JogoMC = new Main(stage);
			JogoMC.x = 0;
			JogoMC.y = 0;
			menuProjectRef.addChild(JogoMC);
			TweenLite.to(JogoMC, 1, { scaleX:1, scaleY:1, ease:Back.easeInOut, onComplete:SomeMenu});
		}
		
		public function SomeMenu():void {
			//menuProjectRef.alpha = 0;
		}
		
		private function Instrucoes(e:MouseEvent):void{
			btnMenusnd.play();
			InstrucoesMC.x = stage.stageWidth / 2
			TweenLite.to(InstrucoesMC, 1, { scaleX:1, scaleY:1, ease:Back.easeInOut});
		}		
		
		public function RemoveHelp(e:Event):void {
			btnMenusnd.play();
			InstrucoesMC.x = -400;
			InstrucoesMC.scaleX = 0;
			InstrucoesMC.scaleY = 0;
		}
		
	}
	
}
  